package com.jlp.source.config;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lingpeng.jiang
 * @create 2022-01-09 14:53
 * @Description //TODO
 **/
@Slf4j
public class DataSourceContextHolder {

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
    public static void setDataSource(String dbType){
        contextHolder.set(dbType);
        log.info("已切换数据源,当前数据源为：{}",dbType);
    }

    public static String getDataSource(){
        return contextHolder.get();
    }

    public static void clearDataSource(){
        contextHolder.remove();
    }
}
